<template>
	<view>
		<navigationTop isBack="true" imgSrc="../../static/img/Logo-ERoad-文字版-1.png"></navigationTop>

		<view class="orderIdBox">
			<view v-if="orderList.orderState!='未支付'">订单号：{{orderDetail.orderId}}</view>
			<view class="hintPayBox" v-if="orderList.orderState=='未支付'" >
				<image src="../../static/img/icon-notice.png" mode="widthFix" ></image>
				12:23:54后将自动取消订单
			</view>
			<view>{{orderList.orderState}}</view>
		</view>

		<view class="thank" v-if="orderList.orderState=='已完成'">
			<text >感谢您的支持，期待下次与你宜路同行</text>
		</view>
		<view class="fareInfBox">
			<view class="timeBox">
				<text>{{orderDetail.orderDay}}</text>
				<text>{{orderDetail.orderTime}}</text>
			</view>

			<view class="siteBox">
				<view class="depart">{{orderDetail.orderDepart}}</view>
				<view class="plate">
					<text>{{orderDetail.plate}}</text>
					<image src="../../static/img/icon-directivity-01.png" mode="widthFix"></image>
				</view>
				<view class="destination">
					<text>{{orderDetail.orderDestination}}</text>
					<text>{{orderDetail.orderDestination}}常平站</text>
				</view>
			</view>
		</view>

		<view class="peer" v-if="orderList.orderState=='待出行'|| orderList.orderState=='未支付'">
			<text >已有25位同行的小伙伴</text>
		</view>
		<!-- 待出行 -->
		<view v-if="orderList.orderState=='待出行'">
			<view class="Box">
				<view class="orderInf">
					<text>订单金额</text>
					<text>￥{{orderList.headList.price}}</text>
				</view>
				<view class="orderInf">
					<text>发车电话</text>
					<text>{{orderList.headList.phone}}</text>
				</view>
				<view class="orderInf">
					<text>订单日期</text>
					<text>{{orderList.headList.orderDate}}</text>
				</view>
				<view class="orderInf">
					<text>乘车座位号</text>
					<text>{{orderList.headList.seat}}</text>
				</view>
				<view class="orderInf">
					<text>乘车人</text>
					<text>{{orderList.headList.rider}}</text>
				</view>
			</view>
			<view class="operation">
				<view>致电客服</view>
				<view @tap="cancelOrder">取消订单</view>
			</view>
		</view>


		<!-- 未支付 -->
		<view v-if="orderList.orderState=='未支付'">
			<view class="Box">
				<view class="orderInf">
					<text>订单金额</text>
					<text style="color: #F13015;">￥{{orderList.headList.price}}</text>
				</view>
				<view class="orderInf">
					<text>优惠券</text>
					<view style="display: flex;">
						<text style="font-weight: 400;">满30-5元</text>
						<image src="../../static/img/back.png" mode="widthFix" style="width: 48rpx; transform: rotate(-90deg);margin-left: 12rpx;"></image>
					</view>
				</view>
				<view class="orderInf">
					<text>订单时间</text>
					<text>{{orderList.headList.orderDate}}</text>
				</view>
				<view class="orderInf">
					<text>乘车座位号</text>
					<text>{{orderList.headList.seat}}</text>
				</view>
				<view class="orderInf">
					<text>乘车人</text>
					<view style="display: flex;">
						<text style="font-weight: 400;">{{orderList.headList.rider}}</text>
						<image src="../../static/img/back.png" mode="widthFix" style="width: 48rpx; transform: rotate(-90deg);margin-left: 12rpx;"></image>
					</view>
				</view>
			</view>

			<view class="operation">
				<view @tap="isConfirm = true">取消订单</view>
				<view @tap="submitOrder">前往支付</view>
			</view>

			
			<view class="confirm" v-show="isConfirm">
				<view class="mask" @click="isConfirm = false" ></view>
				<view class="confirmImg">
					<image src="../../static/img/Logo-ERoad-文字版-1.png" mode="widthFix"></image>
					<text>请确认是否取消该订单</text>
				</view>
				<view class="operation1">
					<view class="toOrder operationBox" @tap="cancelOrder">
						确认取消
					</view>
					<view class="toIndex operationBox" @tap="backOrder">
						返回订单
					</view>
				</view>
			</view>
		</view>

		<!-- 已完成 -->
		<view v-if="orderList.orderState=='已完成'" style="margin-top: 24rpx;">
			<view class="Box">
				<view class="orderInf">
					<text>订单金额</text>
					<text>￥{{orderList.headList.price}}</text>
				</view>
				<view class="orderInf">
					<text>发车电话</text>
					<text>{{orderList.headList.phone}}</text>
				</view>
				<view class="orderInf">
					<text>订单日期</text>
					<text>{{orderList.headList.orderDate}}</text>
				</view>
				<view class="orderInf">
					<text>乘车座位号</text>
					<text>{{orderList.headList.seat}}</text>
				</view>
				<view class="orderInf">
					<text>乘车人</text>
					<text>{{orderList.headList.rider}}</text>
				</view>
			</view>

			<view class="operation">
				<view>致电客服</view>
				<view>删除订单</view>
			</view>
		</view>

	</view>
</template>

<script>
	import navigationTop from '../../components/navigationTop/navigationTop.vue'
	export default {
		data() {
			return {
				orderList: {
					orderState: "待出行",
					headList: {
						price: 168.88,
						phone: 13514642247,
						orderDate: "2023-11-03 08:44",
						seat: "16排A座",
						rider: "李玲珂"
					},
				},
				isConfirm: false,
				orderDetail:{}
			}
		},
		components: {
			navigationTop
		},
		onShow() {
			this.getOrderDetail()
		},
		onLoad(options) {
			this.orderDetail = JSON.parse(decodeURIComponent(options.orderDetail))
			
		},
		
		methods: {
			
			async getOrderDetail(){
				console.log(111)
				console.log(this.orderDetail)
				const res = await this.$myRequest({
					url:"/order/selectDetailsOrder",
					data:{
						orderId:this.orderDetail.orderId
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
					},
				})
				this.orderList.orderState = this.orderDetail.orderState
				this.orderList.headList = {
					price: this.orderDetail.orderPrice,
					phone: res.data.data.stationPhone,
					orderDate: res.data.data.orderDatetime,
					seat: this.orderDetail.orderLocation,
					rider: res.data.data.userName
				}
				console.log(this.orderList)
			},
			// 取消订单
			async cancelOrder () {
				this.isConfirm = false;
				const res = await this.$myRequest({
					url:"/order/cancel",
					method:"POST",
					data:{
						orderId:this.orderDetail.orderId
					},
					header:{
						'content-type': 'application/x-www-form-urlencoded'
					}
				})
				if(res.data){
					uni.showToast({
						title:"取消成功"
					})
					uni.switchTab({
						url:"/pages/order/order"
					})
				}
				console.log(res)
			},
			// 提交订单
			async submitOrder(){
				const res = await this.$myRequest({
					url:"/order/pay",
					method:'POST',
					data:{
						orderId:this.orderDetail.orderId
					},
				})
				if(res.data){
					uni.showToast({
						title:"支付成功"
					})
					uni.switchTab({
						url:"/pages/order/order"
					})
				}
				// console.log(res)
			},

			backOrder() {
				this.isConfirm = false
			}
		}
	}
</script>

<style lang="scss">
	.mask {
	  position: fixed;
	  top: 0;
	  left: 0;
	  right: 0;
	  bottom: 0;
	  z-index: -1;
	}
	.thank{
		height: 66rpx;
		line-height: 66rpx;
		background: #FAFAFA;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		color: #EB6A58;
		padding-left: 24rpx;
		border-bottom: 1rpx solid #EB6A58;
	}
	.orderIdBox {
		height: 88rpx;
		background: #EB6A58;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 24rpx;
		font-family: Inter, Inter;
		font-size: 24rpx;
		font-weight: 400;

		view:nth-child(1) {
			color: #FAFAFA;
		}

		view:nth-child(2) {
			margin-right: 36rpx;
			width: 144rpx;
			height: 44rpx;
			background: #FAFAFA;
			border-radius: 44rpx;
			color: #EB6A58;
			text-align: center;
			line-height: 44rpx;
		}
		.hintPayBox{
			display: flex; 
			align-items: center;
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 800;
			color: #FAFAFA;
			image{
				width: 64rpx;
				margin-right: 16rpx;
			}
		}
	}
	
	.fareInfBox {
		display: flex;
		height: 162rpx;
		background: #FAFAFA;
		border-bottom: 2rpx solid #EB6A58;

		.timeBox {
			display: flex;
			flex-direction: column;
			width: 208rpx;
			font-family: Inter, Inter;
			color: #333333;
			align-items: center;
			justify-content: center;
			border-right: 1rpx dashed #A8A8A8;

			text:nth-child(1) {
				font-size: 28rpx;
				font-family: Inter, Inter;
				font-weight: 400;
			}

			text:nth-child(2) {
				font-size: 48rpx;
				font-weight: bold;

			}
		}

		.siteBox {
			display: flex;
			align-items: center;
			font-size: 36rpx;
			width: 100%;
			font-family: Inter, Inter;
			font-weight: 400;
			color: #333333;
			height: 162rpx;
			justify-content: space-evenly;
			box-sizing: border-box;
			padding-bottom: 8rpx;

			.plate {
				padding-top: 8rpx;
				position: relative;
				height: 162rpx;
				display: flex;
				align-items: center;
				box-sizing: border-box;

				text {
					position: absolute;
					top: 62rpx;
					left: 28rpx;
					font-size: 20rpx;
					font-weight: 500;
					color: #EB6A58;
				}

				image {
					width: 162rpx;
				}
			}

			.destination {
				display: flex;
				flex-direction: column;
				align-items: center;

				text:nth-child(2) {
					font-size: 24rpx;
				}
			}
		}
	}

	.peer {
		height: 66rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		margin-right: 36rpx;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		color: #EB6A58;
	}

	.Box {
		padding-left: 64rpx;
		.orderInf {
			height: 98rpx;
			border-bottom: 2rpx solid #EB6A58;
			display: flex;
			justify-content: space-between;
			align-items: center;
			color: #000000;
			font-family: PingFang SC, PingFang SC;
			font-size: 32rpx;
			padding-right: 48rpx;
			text:nth-child(1) {
				font-weight: 800;
			}
			text:nth-child(2) {
				font-weight: 500;
			}
		}
	}

	.operation {
		margin-top: 48rpx;
		display: flex;
		justify-content: flex-end;

		view {
			width: 200rpx;
			height: 72rpx;
			border-radius: 72rpx;
			border: 2rpx solid #989898;
			text-align: center;
			line-height: 72rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #989898;
		}

		view:nth-child(2) {
			color: #EB6A58;
			border-color: #EB6A58;
			margin: 0 36rpx;

		}
	}
	
	.confirm{
		position: absolute;
		left: 110rpx;
		top: 508rpx;
		width: 434rpx;
		height: 290rpx;
		background: #fff;
		border-radius: 12rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #333333;
		justify-content: space-between;
		z-index: 2;
		.confirmImg{
			width: 434rpx;
			align-items: center;
			display: flex;
			flex-direction: column;
			margin-top: 48rpx;
			image{
				width: 124rpx;
				margin-bottom: 8rpx;
			}
		}
		.operation1{
			width: 100%;
			height: 100rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #545454;
			margin-bottom: 28rpx;
			.operationBox{
				width: 50%;
				height: 100rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}			
			.toOrder{
				border-right: 2rpx solid #A8A8A8;
			}
			.toIndex{
				color: #EB6A58;
			}
			
		}
	}
</style>
